jQuery().ready(function() {
	if ( jQuery('#badgesystem-form').length ) {
		var badge_count = jQuery('#badgesystem-form input:checked').length;
		jQuery('#badgesystem-form .badge-progressbar').progressbar({ value: Math.ceil( badge_count / badge_complete * 100 ) });

		jQuery('#badgesystem-form .form-checkbox').change(function(){
			$this = jQuery(this);
			if ( $this.attr('checked') ) {
				badge_count++;
			} else {
				badge_count--;
			}

			jQuery('#badgesystem-form .badge-progressbar').progressbar({ value: Math.ceil( badge_count / badge_complete * 100 ) });
			jQuery('#badgesystem-form .badge-progress').animate({ height: Math.ceil(badge_count / badge_complete * 256) }, 'slow');
			if ( badge_count == badge_complete ) {
				jQuery('#badgesystem-form .badge-image-large').effect('bounce', { times:3 }, 'slow', function(){
					jQuery('#badgesystem-form .badge-image-wrapper').addClass('badge-complete').append('<p class="badge-complete-msg">Badge Complete!</p>');
				});
			} else {
				jQuery('#badgesystem-form .badge-image-wrapper').removeClass('badge-complete');
				jQuery('#badgesystem-form .badge-complete-msg').remove();
			}
		});
	}
});
